/**
 * table history.
 */
;(function (history) {
	//为hash变化添加一个回调方法
	var showCallback, hideCallback;
	var switchOver = true;
	Desktop.showWithHistory = function (callback) {
		if(switchOver == true)
		{
			showCallback = callback;
			var hashElements = location.hash.split("/");
			if(hashElements[hashElements.length - 1] != "$desktop")
				location.hash += "/$desktop";
		}
	};
	
	Desktop.hideWithHistory = function (callback) {
		if(switchOver == true)
		{
			hideCallback = callback;
			var hashElements = location.hash.split("/");
			if(hashElements[hashElements.length - 1] == "$desktop")
			{
				hashElements.pop();
				hashElements.join("/");
				location.hash = hashElements;
			}
		}
	};
	
	function changeHistory(hash) {
		if(switchOver == true)
		{
			switchOver = false;
			var url = hash.split("/");
			var desktopshow = url[url.length - 1];
			if(desktopshow == "$desktop")
				Desktop.show(function () {
					if(showCallback)
						showCallback();
					$("#_showDesktop").html("隐藏桌面");
					switchOver = true;
				});
			else
			{
				Desktop.hide(function () {
					if(hideCallback)
						hideCallback();
					$("#_showDesktop").html("我的桌面");
					switchOver = true;
				});
			}
		}
	};
	
	//changeHistory(location.hash);
	
	history.pushCallback(changeHistory);
})(history);